﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - TeacherTimeTable" 
*/ 

component 
	displayname="public.service.db.senate.sequence.TeacherTimeTable"  
	output=false 
	accessors=true 
	{

	property type="string" name="TermID" hint="学期代码";
	property type="string" name="TeacherID" hint="教师ID";
	property type="string" name="TimeIndex" hint="时间序号";

	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}

	
	/**
	* @hint "生成排课时间序号"
	* 
	* @Term "学期"
	* @Teacher "教师"
	*/
	public string function getTimeIDX() output=false {
		/* 
			排课时间序号规则 3位代码
		*/
		var nextID = numberFormat(1, "0__");
		
		var sql = "	SELECT
						tidx 
					FROM
						t_teacher_timetable 
					WHERE
						term_id = :termId 
						AND
						tch_id = :teacherId 
					ORDER BY
						tidx DESC";

		var queryObj = new Query(datasource = application.dnsMaster, maxRows = 1);
		queryObj.addParam( name="termId", value=getTermID(), cfsqltype="cf_sql_char" );
		queryObj.addParam( name="teacherId", value=getTeacherID(), cfsqltype="cf_sql_varchar" );		
		var rs_check = queryObj.execute(sql = sql).getResult();

		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = numberFormat((rs_check.tidx + 1), "0__");
		}

		return nextID;
	}
	
	/**
	* @hint "自定义主键规则"
	* 
	* @Term "学期"
	* @Teacher "教师"
	* @TimeIndex "上课时间序列"
	*/
	public string function getID() output=false {
		
		
		var nextID = getTermID() & "," & getTeacherID() & "," & getTimeIndex();

		/* 
			主键生成规则 
			
			教师上课时间编号18位 3位学期代码 , 10位教师职工号 , 3位时间序号

			Unique: TERM_ID, TCH_ID, TIDX
		*/
		return nextID;
	}

}

</cfscript>